package com.meihua.shellapp.activity.personalcenter;

import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.dialog.ShareDialog;
import com.meihua.shellapp.utils.PicassoUtils;
import com.meihua.shellapp.view.FullRoundEdgeImageView;
import com.umeng.socialize.UMShareAPI;

import butterknife.Bind;

/**
 * 作者：lc on 2017/9/30.
 * 邮箱：lc0607live@163.com
 */

public class InvitationFriendActivity extends BaseActivity {

    @Bind(R.id.iv_top_right)
    ImageView iv_top_right;//分享
    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题
    @Bind(R.id.qrcode)
    ImageView qrcode;//二维码图片
    @Bind(R.id.iv_photo)
    FullRoundEdgeImageView iv_photo;//头像
    @Bind(R.id.tv_name)
    TextView tv_name;//名字
    @Bind(R.id.tv_phone)
    TextView tv_phone;//手机号

    @Override
    public int getLayoutId() {
        return R.layout.activity_invitation;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("我的二维码");
//        iv_top_right.setVisibility(View.VISIBLE);
//        iv_top_right.setImageResource(R.drawable.show);
//        iv_top_right.setOnClickListener(this);
    }

    @Override
    public void createLoadData() {
        super.createLoadData();
        bindData();
    }

    /**
     * 绑定数据
     */
    private void bindData() {
        tv_name.setText(MyApplication.getInstance().bean.getName());
        tv_phone.setText(MyApplication.getInstance().bean.getPhone());
        PicassoUtils.getInstance().bindImageData(iv_photo, MyApplication.getInstance().bean.getAvatar());
        PicassoUtils.getInstance().bindImageData(qrcode, MyApplication.getInstance().bean.getEncodes()
                , android.R.color.transparent);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_top_right://分享
                if (Build.VERSION.SDK_INT >= 23) {
                    String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CALL_PHONE, Manifest.permission.READ_LOGS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SET_DEBUG_APP, Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_APN_SETTINGS};
                    ActivityCompat.requestPermissions(this, mPermissionList, 123);
                } else {
                    ShareDialog dialog = new ShareDialog(mContext);
                    dialog.show();
                }
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        UMShareAPI.get(this).release();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        if (requestCode == 123) {

        }
    }

}
